{extend name="public/base"/}
{block name="style"}

<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/bootstrap-editable.css">
<link rel="stylesheet" href="__PUBLIC__/admin/book/css/index.css?v=20221110&times={:time()}" />
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/iconfont.css" />
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/tooltipify.css">

</link>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/plugs/webuploader/webuploader.css">
<link rel="stylesheet" href="//at.alicdn.com/t/c/font_3754223_a1vp94akoxt.css">
<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
{include file="material/_ali_icon" /}
<style>
	.main-box-body .navs .active {
		background: azure;
		color: #03a9f4;
		border: 1px solid #03a9f4;
		border-radius: 5px;
	}

	.table tbody>tr>td {
		padding: 0px 8px;
	}

	.table-hover>tbody>tr:nth-child(odd) {
		background-color: #f9f9f9;
	}

	.table-responsive {
		min-height: 470px;
	}
/* 
	.toolTip {
		display: flex;
		height: 42px;
		align-items: center;
	}

	.toolTip .num {
		font-size: 13px;
		margin-right: 5px;
		color: #9b2805
	} */

	.title {
		font-weight: bold;
		color: #d50000;
		font-size: 14px !important;
		letter-spacing: 1px;
	}

	.status .iconfont {
		vertical-align: middle;
	}

	em {
		color: red;
	}

	a {
		color: #777;
		text-decoration: none;
	}
	.uploadify-button-text{
		position: relative;
		display: inline-block;
		cursor: pointer;
		background: #fff;
		padding: 0px 5px;
		color: #333;
		text-align: center;
		border-radius: 3px;
		overflow: hidden;
		border: 1px solid #ccc;
	}
	em{
		color: red;
	}
	</style>
{/block}
{block name="body"}
<div class="main-box no-header clearfix">
	<!-- 去子模板选择 -->
	{php}$cate_view = $cate_type;{/php}
	{if $cate_view == 'summary'}{include file="book/_summary" /}{/if}
	{if $cate_view == 'book'}{include file="book/_book" /}{/if}
	{if $cate_view == 'version'}{include file="book/_version" /}{/if}
	{if $cate_view == 'datas'}{include file="book/_datas" /}{/if}
	{if $cate_view == 'baidu_text'}{include file="book/_baidu_text" /}{/if}
	{if $cate_view == 'douyin_text'}{include file="book/_douyin_text" /}{/if}
	{if $cate_view == 'weibo_text'}{include file="book/_douyin_text" /}{/if}
	{if $cate_view == 'img'}{include file="book/_img" /}{/if}
	{if $cate_view == 'video'}{include file="book/_video" /}{/if}
	{if $cate_view == 'bgm'}{include file="book/_bgm" /}{/if}
</div>

<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.custom.js"></script>
{include file="material_media/_pub_upload"}
<script>
	
	function changeTable(elem,e){
		$('.'+elem).show().siblings().hide()
		$(e).addClass('active').parent().siblings().children('a').removeClass('active')
		if(elem == 'dataTable'){
			$('.tDiv').height($('.tBody').height() - 59+- 34)
			$('.tableScroll').css({
				'overflow-y':'scroll',
				'height':$('.tBody').height() + 0
			})
		}
		if(elem == 'textTable'){
			$('.addBtn').hide()
			$('#uploadTEXT').show()
			$("#uploadTEXT").SentUploader({
				server:"{:url('Upload/Uploadtxt')}",
				fileNumLimit:1,
				hiddenName: 'text_content',
				hiddenValType:2,
				fileSingleSizeLimit:50*1024*1024,
			});
		}else{
			$('.addBtn').show()
			$('#uploadTEXT').hide()
			$('.addBtn').attr('id','create_'+elem)
		}
		
	}
	$('.addBtn').on('click',function(){
		switch ($(this).attr('id')) {
			case 'create_content':
				var $modal = $('#create-content-modal');
				$modal.modal({backdrop: 'static', keyboard: false});
				break;
			case 'create_verTable':
				var $modal = $('#create-versions-modal');
				$modal.on('shown.bs.modal', function () {
					$('#picker_ebook11').html('<div>上传</div>')
					$("#picker_ebook11").SentUploader({
						server:"{:url('Upload/Uploadtxt')}",
						fileNumLimit:1,
						hiddenName: 'text_content',
						hiddenValType:2,
						fileSingleSizeLimit:50*1024*1024,
					});
				});	
				$modal.modal({backdrop: 'static', keyboard: false});
				break;
			case 'create_dataTable':
				var $modal = $('#create-data-modal');
				$modal.modal({backdrop: 'static', keyboard: false});
				break;
		}
		
	})
	
	$("#uploadTEXT").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});

	// 上传文本
	$("#text_uplpad").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	
	// 上传版本
	$("#versions_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传版本
	$("#versions_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传数据
	$("#data_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传百文
	$("#baidu_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传抖文
	$("#douyin_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
	// 上传微文
	$("#weibo_upload").SentUploader({
		server:"{:url('Upload/Uploadtxt')}",
		fileNumLimit:1,
		hiddenName: 'text_content',
		hiddenValType:2,
		fileSingleSizeLimit:50*1024*1024,
	});
</script>
<!-- 以下为共用的js -->
<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
<script>
// 复制
function copyContent(content, id,reload = true){
    content = content.toString().replace(/<br\/>/g, `
`)
    content = content.replace(/<em>|<\/em>/g,'');
    var oInput = document.createElement('textarea');
    oInput.value = content;
    document.body.appendChild(oInput);
    oInput.select();
    document.execCommand("Copy"); 
    oInput.className = 'oInput';
    oInput.style.display='none';
	layer.msg('复制成功');
    // let source = '{$action}'
    // var url = "{:url('copy')}";
    // $.ajax({
    //     type: "POST",
    //     url,
    //     data:{id,source},
    //     dataType: "json",
    //     success: function(data){
    //         if(data.code==1){
    //             layer.msg('复制成功');
    //             if(reload){
    //                 setTimeout(function(){
    //                     window.location.reload();
    //                 }, 500)
    //             }
    //         }else{
    //             updateAlert("失败，"+data.msg, 'danger');
    //         }
    //     }
    // })
}
//选用素材
function selection(id, reload=true){
	var url = '{:url("selection")}';
    $.ajax({
        type: "POST",
        url,
        data:{id},
        dataType: "json",
        success: function(data){
            if(data.code==1){
                layer.msg('选用成功');
                if(reload){
                    setTimeout(function(){
                        window.location.reload();
                    }, 500)
                }
            }else{
                updateAlert("失败，"+data.msg, 'danger');
            }
        }
    })
}

//多选 
function multipleInput(arr,e){
    if(arr.length!==0){
        arr.forEach((v,index)=>{
            $(e).each((item,elem)=>{
                if(v === $(elem).val()){
                    $(elem).attr("checked",true);
                }
            })
        })
    }
}

$(function() {
	$('#createUrl').on('click',function(){
		var is_rule = '{:checkAuthRule("add")}';
		if(!is_rule){
			layer.msg("你没权限添加");
			return;
		}
		var $modal = $('#create-referral-link-modal');
		$modal.on('shown.bs.modal', function () {
			//默认选择外
			multipleInput('{:stristr($action, "inside")?3:4}'.split(','),$("input:checkbox[name=hot]"));
			$('#picker_ebook').html('<div>上传文案</div>')
			$("#picker_ebook").SentUploader({
				server:"{:url('Upload/Uploadtxt')}",
				fileNumLimit:1,
				uploadEvents: {
					uploadComplete:function(file){}
				},
				listName : 'fileList_ebook',
				hiddenName: 'field_ebook',
				hiddenValType:2,
				fileSingleSizeLimit:50*1024*1024,
				closeX:true
			},
			{
				fileType: 'service',
				filename : 'images',
			});
		});	
		$modal.modal({backdrop: 'static', keyboard: false});
	});
	$("#createreferral").on('click',function(){
		var data = $('.modelform').serializeJson();
		if ( data['book_id'] == undefined) {
			// updateAlert("书名不能为空", 'danger');
			// return false;
		}

		if (data['content'].length==0 && $("#field_ebook").val() == '') {
			updateAlert("内容不能为空", 'danger');
			return false;
		}
		var url = "{:url('add')}";
		$.ajax({
			type: "POST",
			url: url,
			data:data,
			dataType: "json",
			success: function(data){
				if(data.code==1){
					updateAlert(data.msg, 'success');
					setTimeout(function() {	
						window.location.reload();
					}, 100);
				}else{
					updateAlert("添加，"+data.msg, 'danger');
				}
			},
			error : function(e){
				console.log(e.status);
				console.log(e.responseText);
			}
		})
	});
});

//编辑功能
function editreferral(ee, rule=''){
    var is_rule = '{:checkAuthRule('edit')}';
    if(!is_rule && rule!='close_rule'){
        layer.msg("你没权限编辑");
        return;
    }
	$("#batchtxt").remove();
	var jsonStr = $(ee).attr('data-json');
	var $modal = $('#create-referral-link-modal');
	$modal.on('shown.bs.modal', function () {
		$("#referralname").html("修改");
		$("#createreferral").html("修改");
		var json =  eval("(" + jsonStr + ")");
		$('#createspreadid').val(json.id);
		$('#content').val(json.content);
        $("input[name='content']").val(json.content);
		$('#score').val(json.score);
        console.log(json)
        $("input[name=title]").val(json.title);
        $("input[name=type]").val(json.type);
		$("input:radio[name=channel][value="+json.channel+"]").attr("checked",true);
		$("input:radio[name=category_id][value="+json.category_id+"]").attr("checked",true);
		$("input:radio[name=book_id][value="+json.book_id+"]").attr("checked",true);
		$("input:radio[name=magnitude_num][value="+json.magnitude_num+"]").attr("checked",true);
		multipleInput(json.platform_ids.split(','),$("input:checkbox[name=platform_ids]"))
		multipleInput(json.tag_ids.split(','),$("input:checkbox[name=tag_ids]"))
        multipleInput(json.hot.split(','),$("input:checkbox[name=hot]"))

	});
	$modal.on('hide.bs.modal', function () {
		window.location.reload();
	})
	$modal.modal({backdrop: 'static', keyboard: false})
}

$('.panel-body .show').click(function () {
		$(this).parent().parent().siblings().show()
	})
	$('.mask i').click(function () {
		$(this).parent().hide()
	})

//媒体文件 下载 
function downMedia(content,id, reload = true){
    let aDom = document.createElement('a');
    aDom.style.display = 'none';
    aDom.href = content;
    aDom.setAttribute('download', 'name');
    document.body.appendChild(aDom);aDom.click();
    document.body.removeChild(aDom);
}
function playAudio(url,elem){
	var audioDom = $('#oAudio')[0];
	let tests = $(elem).text()
	$.each($('table td a'),function(index,value){
		if($(value).hasClass('accept')){
			$(value).text('试听')
		}
	})
	if(tests == '试听'){
		$(elem).text('暂停')
		audioDom.src = url;
		audioDom.play()
	}else{
		$(elem).text('试听')
		audioDom.pause()
	}
}
</script>
{/block}
